Imports cmplib01
Imports FMPLib01
Imports System.Text

Public Class frmBattlesListing
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents lblBattlesListing As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents pnlTopBorder As System.Windows.Forms.Panel
    Friend WithEvents picCampaignerIcon As System.Windows.Forms.PictureBox
    Friend WithEvents txtTitleBox As System.Windows.Forms.TextBox
    Friend WithEvents rtbBattlesListing As System.Windows.Forms.RichTextBox
    Friend WithEvents btnPrint As System.Windows.Forms.Button
    Friend WithEvents btnOK As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(frmBattlesListing))
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.rtbBattlesListing = New System.Windows.Forms.RichTextBox()
        Me.lblBattlesListing = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.pnlTopBorder = New System.Windows.Forms.Panel()
        Me.picCampaignerIcon = New System.Windows.Forms.PictureBox()
        Me.txtTitleBox = New System.Windows.Forms.TextBox()
        Me.btnPrint = New System.Windows.Forms.Button()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.Panel1.SuspendLayout()
        Me.pnlTopBorder.SuspendLayout()
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.Panel1.BackColor = System.Drawing.Color.LightSkyBlue
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.rtbBattlesListing, Me.lblBattlesListing, Me.Label2})
        Me.Panel1.Location = New System.Drawing.Point(8, 48)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(496, 482)
        Me.Panel1.TabIndex = 22
        '
        'rtbBattlesListing
        '
        Me.rtbBattlesListing.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.rtbBattlesListing.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.rtbBattlesListing.Location = New System.Drawing.Point(8, 32)
        Me.rtbBattlesListing.Name = "rtbBattlesListing"
        Me.rtbBattlesListing.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical
        Me.rtbBattlesListing.Size = New System.Drawing.Size(480, 440)
        Me.rtbBattlesListing.TabIndex = 4
        Me.rtbBattlesListing.Text = ""
        '
        'lblBattlesListing
        '
        Me.lblBattlesListing.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBattlesListing.ForeColor = System.Drawing.Color.Black
        Me.lblBattlesListing.Location = New System.Drawing.Point(16, 6)
        Me.lblBattlesListing.Name = "lblBattlesListing"
        Me.lblBattlesListing.Size = New System.Drawing.Size(160, 26)
        Me.lblBattlesListing.TabIndex = 3
        Me.lblBattlesListing.Text = "Battles Listing"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.Black
        Me.Label2.Location = New System.Drawing.Point(16, 8)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(104, 16)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Select A Battle"
        '
        'pnlTopBorder
        '
        Me.pnlTopBorder.Anchor = ((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.pnlTopBorder.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlTopBorder.Controls.AddRange(New System.Windows.Forms.Control() {Me.picCampaignerIcon, Me.txtTitleBox})
        Me.pnlTopBorder.Name = "pnlTopBorder"
        Me.pnlTopBorder.Size = New System.Drawing.Size(520, 40)
        Me.pnlTopBorder.TabIndex = 21
        '
        'picCampaignerIcon
        '
        Me.picCampaignerIcon.Image = CType(resources.GetObject("picCampaignerIcon.Image"), System.Drawing.Bitmap)
        Me.picCampaignerIcon.Location = New System.Drawing.Point(9, 11)
        Me.picCampaignerIcon.Name = "picCampaignerIcon"
        Me.picCampaignerIcon.Size = New System.Drawing.Size(16, 16)
        Me.picCampaignerIcon.TabIndex = 9
        Me.picCampaignerIcon.TabStop = False
        '
        'txtTitleBox
        '
        Me.txtTitleBox.BackColor = System.Drawing.Color.SteelBlue
        Me.txtTitleBox.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtTitleBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtTitleBox.ForeColor = System.Drawing.Color.WhiteSmoke
        Me.txtTitleBox.Location = New System.Drawing.Point(32, 8)
        Me.txtTitleBox.Multiline = True
        Me.txtTitleBox.Name = "txtTitleBox"
        Me.txtTitleBox.ReadOnly = True
        Me.txtTitleBox.Size = New System.Drawing.Size(312, 26)
        Me.txtTitleBox.TabIndex = 8
        Me.txtTitleBox.Text = "Campaigner [Assign To Battles]"
        '
        'btnPrint
        '
        Me.btnPrint.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.btnPrint.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnPrint.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnPrint.ForeColor = System.Drawing.Color.Black
        Me.btnPrint.Location = New System.Drawing.Point(416, 544)
        Me.btnPrint.Name = "btnPrint"
        Me.btnPrint.TabIndex = 24
        Me.btnPrint.Text = "Print"
        '
        'btnOK
        '
        Me.btnOK.Anchor = (System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right)
        Me.btnOK.BackColor = System.Drawing.Color.LightSkyBlue
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.ForeColor = System.Drawing.Color.Black
        Me.btnOK.Location = New System.Drawing.Point(336, 544)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 23
        Me.btnOK.Text = "OK"
        '
        'frmBattlesListing
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(512, 574)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnPrint, Me.btnOK, Me.Panel1, Me.pnlTopBorder})
        Me.Name = "frmBattlesListing"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Panel1.ResumeLayout(False)
        Me.pnlTopBorder.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ptrGameData As CampaignerGameData
    Private ptrFMPData As FlexMapData

    Shadows Sub ShowDialog(ByRef gameData As CampaignerGameData, ByRef fmp As FlexMapData)

        ' populate the text box with all of the battles information. This will be expanded to show elements
        ' when they are available
        Dim batt As Battle
        Dim battKey As String
        Dim battleList As New StringBuilder()

        ptrGameData = gameData
        ptrFMPData = fmp

        For Each battKey In gameData.Battles_g.HT.Keys
            batt = gameData.Battles_g.Item(battKey)
            ' add each battle
            battleList.Append("--------------------------------------------")
            'battleList.Append(WriteBattle(batt))
        Next

        ' put the battlelist stuff into the richtextbox
        rtbBattlesListing.Text = battleList.ToString

        MyBase.ShowDialog()

    End Sub

    'Private Function WriteBattle(ByVal Batt As Battle) As String
    '    Dim battleString As New StringBuilder()

    '    ' first line is the battle name
    '    battleString.Append(Batt.BattleName & ControlChars.CrLf)

    '    ' second line is the terrain types
    '    battleString.Append("Terrain Description: " & ptrFMPData.TerrainNameAtCoord(Batt.BattleLocation) & ControlChars.CrLf)

    '    ' faction names 
    '    Dim fact As Faction
    '    fact = ptrGameData.Faction_g.Item(CampaignerGameData.CDGKEY_FACTION & Batt.DefendingFactionID)
    '    battleString.Append("Defender: " & fact.FactionName & ControlChars.CrLf)
    '    fact = ptrGameData.Faction_g.Item(CampaignerGameData.CDGKEY_FACTION & Batt.AttackingFactionID)
    '    battleString.Append("Attacker: " & fact.FactionName & ControlChars.CrLf)

    '    ' fifth line skipped
    '    battleString.Append(ControlChars.CrLf)

    '    ' sixth line is the 'defending' players forces involved-> playername: unitname, pv, orders
    '    battleString.Append("Defending Units" & ControlChars.CrLf)
    '    battleString.Append(ListInvolvedUnits(Batt, Batt.DefendingFactionID) & ControlChars.CrLf)

    '    ' after those lines are the rules for the 'defending' player
    '    battleString.Append("Defending Rules Assigned" & ControlChars.CrLf)
    '    battleString.Append(ListAssignedRules(Batt, True) & ControlChars.CrLf)

    '    ' then attacking player forces
    '    battleString.Append("Attacking Units" & ControlChars.CrLf)
    '    battleString.Append(ListInvolvedUnits(Batt, Batt.AttackingFactionID) & ControlChars.CrLf)

    '    ' attacking player rules
    '    battleString.Append("Attacking Rules Assigned" & ControlChars.CrLf)
    '    battleString.Append(ListAssignedRules(Batt, False) & ControlChars.CrLf)

    '    Return battleString.ToString

    'End Function

    'Private Function ListInvolvedUnits(ByVal Batt As Battle, ByVal validFactionID As Int32) As String
    '    ' returns the units involved, from the attacking or defending faction 
    '    Dim unitKey As String
    '    Dim unit As GroundChitType
    '    Dim playKey As String
    '    Dim play As Player
    '    Dim Karayzee As New StringBuilder()
    '    Dim i As Integer
    '    Dim reinforcementString As String


    '    For Each unitKey In Batt.InvolvedChits.Keys
    '        unit = Batt.InvolvedChits.Item(unitKey)
    '        reinforcementString = ""
    '        If unit.OwningFaction = validFactionID Then
    '            ' add this unit and his point value... and well I guess the owning player too...
    '            For Each playKey In ptrGameData.Players.Keys

    '                play = ptrGameData.Players.Item(playKey)
    '                If play.PlayerID = unit.OwningPlayer Then
    '                    If unit.CurrentBattlePosture = BattlePosture_cgd.AttackingSupport Or unit.CurrentBattlePosture = BattlePosture_cgd.DefendingSupport Then
    '                        reinforcementString = "Reinforcement"
    '                    End If
    '                    Karayzee.Append(" " & unit.Name & " [" & play.PlayerName & "] " & reinforcementString & ControlChars.CrLf)
    '                    If TypeOf unit Is BattleGroup Then
    '                        Karayzee.Append(getbattlegrouptext(unit))
    '                    End If
    '                    'Dim ele As GroupableElement
    '                    'For Each ele In unit.ChitElements
    '                    '    Karayzee.Append("      " & ele.Count & "x " & ele.ElementTypeName & ControlChars.CrLf)
    '                    'Next
    '                    Exit For
    '                End If
    '            Next
    '        End If
    '    Next

    '    Return Karayzee.ToString

    'End Function

    'Private Function GetBattlegroupText(ByRef bg As BattleGroup) As String
    '    Dim un As GroundChitType
    '    Dim cha As New StringBuilder

    '    For Each un In bg.Units
    '        If TypeOf un Is BattleGroup Then
    '            cha.Append(GetBattlegroupText(un) & ControlChars.CrLf)
    '        Else
    '            cha.Append(" ==" & un.Name & ControlChars.CrLf)
    '        End If
    '    Next

    '    Return cha.ToString
    'End Function

    'Private Function ListAssignedRules(ByVal Batt As Battle_2, ByVal DefenderPOV As Boolean) As String
    '    Dim ruleKey As String
    '    Dim asgnRule As AssignedRule
    '    Dim Karayzee As New StringBuilder
    '    'Dim HT As Hashtable
    '    Dim col As Collection


    '    If DefenderPOV = True Then
    '        '    HT = Batt.DefenderAssigned
    '        col = Batt.DefenderAssigned
    '    Else
    '        '   HT = Batt.AttackerAssignedRules
    '        col = Batt.AttackerAssigned
    '    End If

    '    '        For Each ruleKey In HT.Keys
    '    '       asgnRule = HT.Item(ruleKey)
    '    For Each asgnRule In col
    '        Karayzee.Append(" *" & asgnRule.DisplayName & "[" & asgnRule.Count & "]" & ControlChars.CrLf)
    '        Karayzee.Append("   " & asgnRule.RuleText & ControlChars.CrLf)
    '    Next


    '    'If HT.Count = 0 Then
    '    If col.Count = 0 Then
    '        Karayzee.Append("<none>" & ControlChars.CrLf)
    '    End If

    '    Return Karayzee.ToString

    'End Function

    'Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
    '    Me.Hide()
    'End Sub

    'Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
    '    MessageBox.Show("Like printed, man. Totally printed.")

    'End Sub

End Class
